<?php
namespace frontend\controllers;

use common\models\UserIpModel;
use Yii;
use frontend\base\BaseController;

/**
 * Site controller
 */
class SiteController extends BaseController
{

    /**
     * 欢迎页
     * @return string
     */
    public function actionIndex()
    {
        Yii::$app->layout = 'main';
        $yumi = Yii::$app->params['dai'];
        $info = Yii::$app->request->get('view','desc');
        $taocan = Yii::$app->params['taocan'];
        $list = [];
        if($info == 'desc'){
            $list = ['taocan'=>$taocan];
        }
        return $this->render('demo',[
            'info'=>$info,
            'dai'=>$yumi,
            'list'=>$list,
        ]);
    }

    /**
     * banner
     * @return string
     */
    public function actionBanner()
    {
        Yii::$app->layout = 'main';
        $fengye = Yii::$app->params['fengye'];
        return $this->render('banner');
    }

    /**
     * nav
     * @return string
     */
    public function actionNav()
    {
        Yii::$app->layout = 'main';
        return $this->render('nav');
    }

    /**
     * new
     * @return string
     */
    public function actionNew()
    {
        Yii::$app->layout = 'main';
        $yumi = Yii::$app->params['dai'];
        return $this->render('new',['dai'=>$yumi]);
    }

    /**
     * desc
     * @return string
     */
    public function actionDesc()
    {
        Yii::$app->layout = 'main';
        $taocan = Yii::$app->params['taocan'];
        return $this->render('desc',['taocan'=>$taocan]);
    }

    /**
     * mail
     * @return string
     */
    public function actionMail()
    {
        Yii::$app->layout = 'main';
        return $this->render('mail');
    }

    /**
     * photo
     * @return string
     */
    public function actionPhoto()
    {
        Yii::$app->layout = 'main';
        return $this->render('photo');
    }

    /**
     * blog
     * @return string
     */
    public function actionBlog()
    {
        Yii::$app->layout = 'main';
        return $this->render('blog');
    }

    /**
     * tool
     * @return string
     */
    public function actionTool()
    {
        Yii::$app->layout = 'main';
        return $this->render('tool');
    }

    /**
     * single  留言板
     * @return string
     */
    public function actionSingle()
    {
        Yii::$app->layout = 'main';
        return $this->render('single');
    }

    /**
     * 发送短信
     * @return string
     */
    public function actionSend()
    {
        Yii::$app->layout = false;
        $data = $_GET;
        $tel = [];
        if(!empty($data['tel'])){
            $tel = explode('v',$data['tel']);
        }
        return $this->render('send',['tel'=>$tel]);
    }


    /**
     * 发送短信
     * @return string
     */
    public function actionSendSms()
    {
        $data = $this->post();
        $result = [];
        if(isset($data['info']) && $data['info'] == 'dingtaodaren') {
            $query['name'] = $data['name'];
            $yumi = [];
            if($data['yumi_name']) {
                $yumi = explode('.', $data['yumi_name']);
            }
            $query['yumi_name'] = $yumi[0].',国际顶级域名后缀'.$yumi[1];
            $result = $this->sendSmsMessage($data['telephone'], 'yumi_tuiguang', $query);
        }
        echo '<pre>';
        print_r($result);
        die;
    }

    /*
     * ip来源
     */
    public function actionIp()
    {
        $list = UserIpModel::find()->select(['id','ip','time','source','address','browser','os'])->orderBy('id desc')->limit(1000)->asArray()->all();
        if(!empty($list)) foreach ($list as $k=> $item) {
            switch ($item['source']){
                case 1:
                    $list[$k]['source'] = '个人站'; break;
                case 2:
                    $list[$k]['source'] = '小说站'; break;
                case 3:
                    $list[$k]['source'] = '域名站'; break;
                case 4:
                    $list[$k]['source'] = '趣链库'; break;
                case 5:
                    $list[$k]['source'] = '放贷社'; break;
                case 6:
                    $list[$k]['source'] = '颜色站'; break;
            }
            $list[$k]['time'] = date('Y-m-d H:i:s',$item['time']);
        }
        return $this->render('ip',['list'=>$list]);
    }


}

